<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    dialog-width="1130px"
    :page-show="pageShow"
    @dialog-close="dialogClose"
  >
    <template #toolPanel />
    <template #searchPanel>
      <search-panel :show-add-button="false" :show-search-button="true"
                     labelWidth="73" @search="search" :left="true">
        <el-form-item label="运营商:" prop="operatoruid">
          <el-select v-model="filters.operatoruid" clearable filterable collapse-tags placeholder="请选择运营商">
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in operator"
              :key="item.operatoruid"
              :label="item.operatorname"
              :value="item.operatoruid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="省份:" prop="provinceuuid">
          <el-select v-model="filters.provinceuuid" clearable filterable collapse-tags placeholder="请选择省份">
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in info"
              :key="item.provinceuuid"
              :label="item.provincename"
              :value="item.provinceuuid">
              <span style="float: left">{{ item.provincename }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ item.label }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="业务类型:" prop="busuuid">
          <el-select v-model="filters.busuuid" clearable filterable placeholder="请选择业务类型">
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in bus"
              :key="item.busuuid"
              :label="item.busname"
              :value="item.busuuid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分销商:" prop="useruuid">
          <el-select v-model="filters.downId" clearable placeholder="请选择分销商" filterable >
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in users"
              :key="item.user.useruuid"
              :label="item.user.username"
              :value="item.user.useruuid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="供货商:" prop="useruuid"  >
          <el-select v-model="filters.upId" clearable placeholder="请选择供货商" filterable filterable >
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in userUps"
              :key="item.user.useruuid"
              :label="item.user.username"
              :value="item.user.useruuid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="面值:">
          <el-select v-model="filters.downfacevalue" clearable filterable   placeholder="请面值">
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in downfacevalues"
              :key="item.id"
              :label="item.id"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :current="start"
        :width="222"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <template #action="{row}">
          <el-input-number v-model="row.orderSort" controls-position="right"  @change="handleChange(row)" :min="1" :max="100"></el-input-number>
        </template>
      </data-table>
    </template>

    <template #dialog>

    </template>

  </base-layout>
</template>

<script>
import baseMixin from '@/mixins/base'
import util from '../../../utils/util'
import {queryStrategyPage,updateStrategy} from '@/api/downapi'
import {findAllUpShopInfo,findOpeProBusShop,findAllDownShopInfo,findAllChannel} from '@/api/utilsapi'
import moment from 'moment';

export default {
  name: 'producttimer',
  mixins: [
    baseMixin({
      idName: 'id',
      findData:queryStrategyPage,
      format(res) {
        return res.map(data => {
          return data
        })
      }
    })
  ],
  data() {
    return {
      pageShow: true,
      dialogData:{},
      users:[],
      tableColumnAttributes: [
        { name: '运营商', value: 'operatorName' },
        { name: '省份', value: 'provinceName' },
        { name: '业务类型', value: 'busname' },
        { name: '面值', value: 'status' },
        { name: '分销名称', value: 'userDown' },
        { name: '分销产品名称', value: 'productName' ,width:150},
        { name: '分销折扣', value: 'downdiscount' },
        { name: '供货名称', value: 'userUp',width:110},
        { name: '供货产品名称', value: 'upName' ,width:150},
        { name: '供货折扣', value: 'updiscount' },
        { name: '执行顺序', value: 'orderSort' },
      ],
      filters: {
        upId:'',
        downfacevalue:'',
        downId:'',
        provinceuuid: '',
        busuuid: '',
        status: '' ,
        operatoruid: ''
      },
      userUps:[],
      operator: [],
      downfacevalues:[],
      info: [],
      bus: [],
    }
  },
  methods: {
    async search(form){
      let para = {
        start: 0,
        pageSize: 10,
        userUp:this.filters.upId,
        userDown:this.filters.downId,
        provinceuuid:  this.filters.provinceuuid == "0" ? "" : this.filters.provinceuuid,
        busuuid: this.filters.busuuid == "0" ? "" : this.filters.busuuid,
        status: (this.filters.downfacevalue == "0" || this.filters.downfacevalue.length == 0)? "" : this.filters.downfacevalue  ,
        operatoruid: this.filters.operatoruid == "0" ? "": this.filters.operatoruid,
      };
      this.searchOptions = para;
      this.setTableData()
    },
    async findAllUserShopInfo(){
      let para = {useruuid:''};
      const result = await findAllUpShopInfo(para);
      this.userUps = result.data;
    },
    findOpeProBusShop(){
      let para = {sdffds: ''};
      findOpeProBusShop(para).then(datas => {
         this.operator = datas.data.operator;
         this.info = datas.data.info;
         this.bus = datas.data.bus;
      });
    },
    findAllDownShopInfo:function(){
      let para = {useruuid: this.$store.getters.useruuid};
      findAllDownShopInfo(para).then(datas => {
        if(datas.data){
          this.users = datas.data;
        }
      });
    },
    findAllChannel(){
      let para = {
        province : ""
      };
      findAllChannel(para).then((datas) => {

         if(datas.data){
           datas.data.forEach(item =>{
            this.downfacevalues.push({id:item,value:item});
          });
        }
      });
    },
    handleChange(row){
      updateStrategy(row).then(datas => {
        this.resultSuccess(datas);
      });
    }
  },
  mounted() {
    this.findAllChannel();
    this.findAllUserShopInfo();
    this.findOpeProBusShop();
    this.findAllDownShopInfo();
  }
}
</script>
